package engine.logic.tips
{
	import engine.data.ModelLocator;
	import engine.data.SceneObject;
	import engine.data.ViewObject;
	
	import newx.BaseObject;
	import newx.com.config.StaticIni;
	import newx.com.control.NxToolTips;


	public class TipsManage
	{
		private static var _itemMaxTips:ItemMaxTips = new ItemMaxTips();
		
		public function TipsManage()
		{
		}
		
		/**
		 * 用普通文字显示tips
		 * @param str	要显示的字符串
		 * 
		 */		
		public static function showTips(str:String):void
		{
			hideTips();
			NxToolTips.ShowInfo(str);
		}
		
		/**
		 * 显示技能tips
		 * @param configID	技能的configID
		 * 
		 */		
		public static function showSkillTips(configID:uint,nextConfigID:uint = -1,tipsBool:Boolean = true):void
		{
			hideTips();
			NxToolTips.ShowInfo(new SkillTips().getStr(configID,nextConfigID,tipsBool));
		}
		
		/**
		 * 现实简单物品的tips
		 * @param configID		物品的configID
		 * @param bindType		绑定类型
		 * @oaran bindStatus	绑定状态
		 */		
		public static function ShowItemTips(configID:uint, bindType : int = 0, bindStatus : int = 0):void
		{	
			hideTips();
			NxToolTips.ShowInfo(new ItemTips().getStr(configID,bindType,bindStatus));
		}
		
		/**
		 * 现实简单物品的tips
		 * @param configID	物品的configID
		 * '
		 */		
		public static function ShowItemTipsWithBuyPrice(equipObj:BaseObject,captitalType:int,price:int,castleStatus:int):void
		{			
			hideTips();
			var 	configID:int	=	equipObj.GetProperties("ConfigID");
			var		itemObj:Object	=	StaticIni.getIniObj(String(configID));
			var		part1:String	=	"";
			var		part2:String	=	"<br>";
			
			if(itemObj["EquipType"])
			{
				part1	=	_itemMaxTips.getStr(equipObj,[],false,null);
			}else{
				part1	=	new ItemTips().getStrNoPrice(configID);
			}
			
			var roleObj	:SceneObject =	ModelLocator.getInstance().scene.Role;
			//价格tips 
			var priceTip : String = "";
			//城堡爵位tips
			var castleStatueTip : String = "";
			
			//原价
			priceTip = "<br>" +StaticIni.getSwfLangStr("UIStr_1000296")+
				StaticIni.getIniVar("t_"+configID,"Prize")+
				StaticIni.getSwfLangStr("Tips_CapitalType"+StaticIni.getIniVar("t_"+configID,"Type"));
			//折扣价
			//priceTip += "<br>"+StaticIni.getSwfLangStr("UIStr_1000989")+price+ 
			//	StaticIni.getSwfLangStr("Tips_CapitalType"+captitalType) + "<br>";
			
			var	priceType:String = "";
			//城堡贡献
			if(captitalType == 3 ){
				priceType = "CastlePoint";
			}else if(captitalType == 2){
				//竞技场荣誉
				priceType = "CompetePoint";
			}else if(captitalType == 0){
				//普通货币
				priceType = "GoldCoin";
			}
			
			if(priceType != ""){
				if(roleObj.GetPropertiesEx(priceType) < price){
					priceTip =  "<font color='#f00000'>" + priceTip + "</font>";
				}
			}
			
			//自己城堡地位大于要求
			if(castleStatus != 0 ){
				if(roleObj.GetPropertiesEx("CastlePoint") < price){
					priceTip =  "<font color='#f00000'>"+priceTip+"</font>";
				}
				
				if(!itemObj["EquipType"])
				{
					var myCastleStatus:int = roleObj.GetPropertiesEx("CurCastleStatusId")
					castleStatueTip = StaticIni.getSwfLangStrVar("UIStr_1000580",[StaticIni.getSwfLangStr("CastleStatus_"+castleStatus)]) +"<br>";		
					if( myCastleStatus == 0 || myCastleStatus > castleStatus){
						castleStatueTip = "<font color='#f00000'>"+castleStatueTip+"</font>";
					}
				}
			}
			
			part2 = priceTip + castleStatueTip;
			
			if(itemObj["EquipType"]){
				var compareStr:Array = getCompareStrArray(itemObj["EquipType"],part1+part2);				
				NxToolTips.ShowInfoArray(compareStr);				
			}else{				
				NxToolTips.ShowInfo(part1+part2);
			}
		}
		
		/**
		 * 显示装备物品的tips
		 * @param configID	套装物品的configID
		 * @param itemHard	耐久
		 * @param currentConfigIdArr	身上装备的configID数组
		 * @oaran special	特殊属性
		 * @param bindType	绑定类型
		 * @oaran bindStatus	绑定状态
		 */		
		public static function ShowItemMaxTips(
			equipObj			:BaseObject,
			currentConfigIdArr	:Array,
			isPrice				:Boolean=true):void
		{
			hideTips();
			NxToolTips.ShowInfo(_itemMaxTips.getStr(equipObj,
				currentConfigIdArr,
				isPrice));
		}
		
		/**
		 * 显示装备物品的tips 并比较当前装备
		 * @param configID	套装物品的configID
		 * @param itemHard	耐久
		 * @param currentConfigIdArr	身上装备的configID数组
		 * @param type		装备位置
		 * @oaran special	特殊属性
		 * @param bindType				绑定类型
		 * @oaran bindStatus				绑定状态		 
		 */		
		public static function ShowItemCompareTips(
			equipObj			:BaseObject,
			currentConfigIdArr	:Array,
			isPrice				:Boolean=true):void
		{
			hideTips();
			var type:String;
			
			if(equipObj.CheckProperties("EquipType"))
			{
				type	=	equipObj.GetProperties("EquipType")
			}
			else
			{
				type	=	StaticIni.getIniVar(
					equipObj.GetProperties("ConfigID"),"EquipType");
			}
			
			if(type != "")
			{
				//装备物品
				var equStr:String = _itemMaxTips.getStr(equipObj,
					currentConfigIdArr,
					isPrice);
				
				var nowEquStr:Array = getCompareStrArray(type,equStr);
				
				NxToolTips.ShowInfoArray(nowEquStr);
			}
		}
		
		/** 装备比较字符串集合
		 * 
		 * @param t	被比较的装备类型
		 * @param equipStr 被比较的装备信息字符串
		 * @return 字符串集合
		 * 
		 */		
		private static function getCompareStrArray(t:String, equipStr:String):Array
		{
//			hideTips();
//			var strArr:Array = new Array();
//			strArr.push(equipStr);
//			
//			
//			//目前装备				
//			var v				:View 		= ModelLocator.getInstance().scene.GetView(View.VIEWPORT_EQUIP);
//			var index			:int 		= PackUI.getInstance().GetEquipIndexByType(t);		
//			
//			//是否有装备
//			if(!v.CheckProperties(index.toString()))
//			{
//				if(t != GameDefine.EquipType_Ring && t != GameDefine.EquipType_Adorn)
//				{
//					return strArr; 
//				}
//				switch(t)
//				{
//					case GameDefine.EquipType_Ring:
//						index = (index==11)?7:11;
//						break;
//					case GameDefine.EquipType_Adorn:
//						index = (index==12)?13:12;
//						break;
//				}
//				if(!v.CheckProperties(index.toString()))
//				{
//					return strArr;
//				}
//			}
//			
//			//取当前所有装备id
//			var equipArr:Array = new Array();
//			for(var i:int=1; i < 17; ++i)
//			{
//				if(v.CheckProperties(i.toString()))
//				{
//					var temp:ViewObject = v.GetProperties(i.toString());
//					equipArr.push(temp.GetProperties("ConfigID"));
//				}
//			}
//			
//			var ntObj:ViewObject = v.GetProperties(index.toString());
//			var nowEquStr:String = getNowEquipStr(ntObj, equipArr);			
//			strArr.push(nowEquStr);			
//			
//			//装备是戒指或者饰品
//			if(t != GameDefine.EquipType_Ring && t != GameDefine.EquipType_Adorn)
//			{
//				return strArr; 
//			}
//			var otherIndex:int; 
//			switch(t)
//			{
//				case GameDefine.EquipType_Ring:
//					otherIndex = (index==11)?7:11;
//					break;
//				case GameDefine.EquipType_Adorn:
//					otherIndex = (index==12)?13:12;
//					break;
//			}
//			
//			if(!v.CheckProperties(otherIndex.toString()))
//			{
//				return strArr;
//			}
//			
//			ntObj = v.GetProperties(otherIndex.toString());
//			nowEquStr = getNowEquipStr(ntObj, equipArr);			
//			strArr.push(nowEquStr);
			
//			return strArr;
			return [];
		}
		
		/** 获取当前装备信息字符串
		 * 
		 * @param ntObj	装备对象
		 * @param equipArr 目前所有已装备id集合
		 * @return 信息字符串
		 * 
		 */		
		private static function getNowEquipStr(ntObj:ViewObject, equipArr:Array):String
		{	
			hideTips();
			var nbindType 		:int 		= ntObj.GetPropertiesEx("BindType");
			var nbindStatus 	:int 		= ntObj.GetPropertiesEx("BindStatus");
			var ntempHoleCoun	:Number		= ntObj.GetPropertiesEx("HoleCount");
			
			//附加属性
//			var naddProps :Array	=	[];
//			var len:Number		=	Number(StaticIni.getIniVar("ProTipList","addPropNum"));
//			for(var j:int = 0; j < len; ++j){
//				naddProps.push( ntObj.GetPropertiesEx("AddPropNo"+j) );
//			}
			
			var st:String = "<p align='center'>"+StaticIni.getSwfLangStr("F_Gem_EquipCompare") + "</p>";
			
			var nowEquStr:String = _itemMaxTips.getStr(ntObj,
				equipArr,
				true);
			return st + nowEquStr;			
		}
		
		
		/**
		 * 隐藏tips
		 * 
		 */		
		public static function hideTips():void
		{
			NxToolTips.hide();
		}
	}
}
